package com.jarvis.pzz.modules.my.view;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jarvis.pzz.R;
import com.jarvis.pzz.common.BaseActivity;
import com.jarvis.pzz.common.ResponseData;
import com.jarvis.pzz.models.FeedBackModel;
import com.jarvis.pzz.modules.my.adapter.FeedBackListAdapter;
import com.jarvis.pzz.seervers.RequestService;
import com.jarvis.pzz.util.net.RequestApi;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler2;
import in.srain.cube.views.ptr.PtrFrameLayout;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by jarvis.liu on 2016-11-02.
 */

public class FeedbackActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.rel_left)
    RelativeLayout rel_left;
    @BindView(R.id.rel_right)
    RelativeLayout rel_right;
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_feed_back)
    TextView tv_feed_back;
    @BindView(R.id.ed_feed_value)
    EditText ed_feed_value;


    private RequestService service;

    @Override
    public int getLayoutId() {
        return R.layout.activity_feed_back;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        setStatusWhite(true);
        service = RequestApi.create(RequestService.class);
        setListener();
    }

    /**
     * 设置监听事件
     */
    public void setListener() {
        rel_left.setOnClickListener(this);
        tv_feed_back.setOnClickListener(this);
    }

    private void loadData() {
        showDialog("loading");
        Call<ResponseData> responseDataCall = service.saveFeedback(ed_feed_value.getText().toString());
        responseDataCall.enqueue(new Callback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                disMiss();
                if (response.body() != null) {
                    int resultCode = response.body().getResultCode();
                    if (resultCode == 200) {
                        showTextToast(response.body().getMessage());
                        finish();
                    } else {
                        showTextToast(response.body().getMessage());
                    }
                } else {
                    showTextToast("请求失败");
                }
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                disMiss();
                showTextToast(RequestApi.detailError(t));
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rel_left:
                finish();
                break;
            case R.id.tv_feed_back:
                if(TextUtils.isEmpty(ed_feed_value.getText().toString())){
                    showTextToast("请先输入反馈内容");
                }else {
                    loadData();
                }
                break;

        }
    }
}
